<script setup>
  import { onBeforeRouteLeave, useRoute } from 'vue-router';
  import { watch, reactive } from 'vue';
  import { GetExStatBlockProfit } from '@/api/exdoctor/exstat'
  const appRoute = useRoute()

  const pageData = reactive({
    data: {}
  })

  const getOverview = () => {
    const params = {
      fn: appRoute.query.fn,
      start: appRoute.query.start,
      end: appRoute.query.end
    }
    GetExStatBlockProfit(params.fn, params.start, params.end).then((res) => {
      // console.log(res)
      pageData.data = res.data
    })
  }

  const watchRouteTs = watch(() => appRoute.query._ts, () => {
    getOverview()
  }, { immediate: true})

  onBeforeRouteLeave(() => {
    watchRouteTs()
  })
</script>
<template>
  <div class="view-container">
    <div class="title-box">
      <div class="title">交易统计分析</div>
      <div class="sub-title">- 板块盈亏分析 -</div>
    </div>
    <el-divider content-position="left">1、板块每月盈亏</el-divider>
    <div class="img-text">
      <el-image class="img-show" :src="pageData.data.bp_img_month_url" fit="fill">
        <template #error>
          <div class="error-slot">
            数据加载中...
          </div>
        </template>
      </el-image>
      <div class="txt-show">
        {{ pageData.data.bp_txt_month }}
      </div>
    </div>
    <el-divider content-position="left">2、板块盈亏</el-divider>
    <div class="img-text">
      <el-image class="img-show" :src="pageData.data.bp_img_url" fit="fill">
        <template #error>
          <div class="error-slot">
            数据加载中...
          </div>
        </template>
      </el-image>
      <div class="txt-show">
        {{ pageData.data.bp_txt }}
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
  .view-container {
    padding: 0 20px 10px 20px;
    .title-box {
      // text-align: left;
      margin: 10px 0;
      line-height: 30px;
      .title {
        font-size: 22px;
        font-weight: 600;
        .sub-title {
          color: #444;
          font-size: 15px;
          
        }
      }
    }
    .img-text {
      .img-show {
        width: 660px;
        height: 330px;
        .error-slot {
          display: flex;
          justify-content: center;
          align-items: center;
          height: 100%;
          color: var(--el-text-color-secondary);
        }
      }
      .txt-show {
        line-height: 30px;
        margin-top: 10px;
        text-indent: 2em;
        background-color: #e7edfa;
        padding: 2px 10px;
        border-radius: 4px;
      }
    }
  }
</style>

